package com.zttek.videoShareProject.modules.web;


import com.zttek.videoShareProject.common.base.MyBaseController;
import com.zttek.videoShareProject.common.json.CommentVO;
import com.zttek.videoShareProject.common.keyword.CommentUttil;
import com.zttek.videoShareProject.modules.model.Comment;
import com.zttek.videoShareProject.modules.service.ICommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import java.util.Date;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author CBY
 * @since 2018-07-03
 */
@Controller
@RequestMapping("/comment")
public class CommentController extends MyBaseController {
    @Autowired
    private ICommentService commentService;
//    url：http://localhost:8080/vss/comment/add_comment  method:post
//    提交评论数据
//    {
//        video_id:
//        user_id:
//        context：
//    }
//    返回
//    {
//        success:true
//    }

    @ResponseBody
    @RequestMapping(value = "add_comment",method = RequestMethod.POST)
    public Object addComment(@RequestBody CommentVO.AddComment addComment) {
        Comment comment = addComment.getComment();
        CommentVO.CommentForAddReturn commentForAddReturn = null;
        try {
            commentForAddReturn = commentService.addComment(comment);
        } catch (Exception e) {
            e.printStackTrace();
            renderError();
        }
        return renderSuccess(commentForAddReturn);
    }

    @ResponseBody
    @RequestMapping(value = "comments",method = RequestMethod.GET)
    public Object selectCommentByVideoId (@RequestParam("video_id") Long video_id){
        List<CommentVO.CommentForAddReturn> list = null;
        try {
            list=commentService.selectCommentByVideoId(video_id);
        } catch (Exception e) {
            e.printStackTrace();
            renderError();
        }
        return renderSuccess(list);
    }


//    @ResponseBody
//    @RequestMapping("addUser")
//    public Result addUser(@RequestParam(value = "account")String account,
//
//                          @RequestParam(value="email")String email,
//                          @RequestParam(value ="password")String password,
//                          @RequestParam(value ="checkPassword")String checkPassword,
//                          @RequestParam(value="phone")String phone,
//                          @RequestParam(value="optionsRadios")String sex
//    ){
//        Result result=new Result();
//        if(password.equals(checkPassword)) {
//            User user = new User();
//            user.setAccount(account);
//            user.setEmail(email);
//            user.setPassword(password);
//            user.setTelephone(phone);
//            user.setScore(0);
//            user.setStatus(0);
//            user.setUserType(1);
//            System.out.println("a");
//            Date date=new Date();
//            System.out.println(date);
//            user.setCreateDate(date);
//            if (sex.equals("male")) {
//                user.setSex(0);
//            } else {
//                user.setSex(1);
//            }
//            if(iUserService.insert(user)){
//                result.setSuccess(true);
//                result.setMsg("注册成功");
//            }else{
//                result.setSuccess(false);
//                result.setMsg("账号名已被占用");
//            }
//        }else{
//            result.setSuccess(false);
//            result.setMsg("密码不一致");
//        }
//        return result;
//    }
}
